*JCR UED replication figures 1-2*

*change directory to where you saved data*
cd "folder name"
use "UED JCR repdata finalsubm.dta", clear
tsset cowcode year

*Figure 1, scarring torture and terrorism*
*constrain sample to same N in all models, use model with smallest N*
xtnbreg gtddomevents  spLag_domlag ln_stealthlag ln_scarringlag restacclag ln_reportcountlag  speechlag ljilag revphysint_notortlag  ln_unstatedlag  ln_cgdplag ln_poplag democracylag durablelag i.year , fe
gen sample=1 if e(sample)
*Run model 1*
nbreg gtddomevents gtddomavg spLag_domlag ln_stealthlag ln_scarringlag  ln_cgdplag ln_poplag democracylag durablelag i.year if sample==1, cluster(cowcode)
margins,  atmeans at(ln_scarringlag=(0(0.1)5) democracy=(1)) vsquish
marginsplot, recast(line) plot1opts(lpattern(-)) recastci(rline)  ciopts(color(gs13)) xtitle("Scarring Torture, logged") title("") legend(off) addplot(kdensity ln_scarringlag, yaxis(2)  yscale(alt axis(2))) saving(scarring1.gph, replace)

*Figure 2, Significant Variables in Models 1-4, table 1*
*Base model*
nbreg gtddomevents gtddomavg spLag_domlag  ln_scarringlag ln_stealthlag ln_cgdplag ln_poplag democracylag durablelag i.year if sample==1, cluster(cowcode)
margins, dydx( spLag_domlag  ln_scarringlag ln_stealthlag ln_poplag) atmeans post
est store marg1
*Information*
nbreg gtddomevents gtddomavg spLag_domlag  ln_scarringlag ln_stealthlag restacclag ln_reportcountlag  ln_cgdplag ln_poplag democracylag durablelag i.year if sample==1, cluster(cowcode)
margins, dydx( spLag_domlag  ln_scarringlag ln_stealthlag restacclag ln_reportcountlag  ln_cgdplag) atmeans post
est store marg2
*Institutional*
nbreg gtddomevents gtddomavg spLag_domlag  ln_scarringlag ln_stealthlag restacclag ln_reportcountlag speechlag ljilag  ln_cgdplag ln_poplag democracylag durablelag i.year if sample==1, cluster(cowcode)
margins, dydx( spLag_domlag  ln_scarringlag ln_stealthlag restacclag ln_reportcountlag  ln_cgdplag ) atmeans post
est store marg3
*HR environment*
nbreg gtddomevents gtddomavg spLag_domlag  ln_scarringlag ln_stealthlag restacclag ln_reportcountlag speechlag ljilag l.ln_unstatedlag revphysint_notortlag ln_cgdplag ln_poplag democracylag durablelag i.year if sample==1, cluster(cowcode)
margins, dydx( spLag_domlag  ln_scarringlag ln_stealthlag restacclag ln_reportcountlag speechlag ljilag  revphysint_notortlag ln_cgdplag ) atmeans post
est store marg4
coefplot (marg1, lab(Model 1)) (marg2, lab(Model 2)) (marg3, lab(Model 3)) (marg4, lab(Model 4)),  xline(0, lpattern(_) )  ciopts(recast(rcap)) saving(scarringsmargins.gph, replace)

drop sample


